<?php
/****************************************************************************

	COPYRIGHT(C) WWW.MAXSI.DK, MAXSI SOFTWARE, SORTIE 2009
	ALL RIGHTS RESERVED

	Maxsi Distribution Shared/ Branch
	Scripts shared by the MasterServer/ and ContentServer/ Branch of the Maxsi
	Distribution Server-Side Code Branches.
		
	Bandwidth.php
	Functions to log the amount of bandwidth used.

****************************************************************************/

	function md_creditbandwidthdb($contentarchiveid, $amount, $date)
	{
		global $md_sql_row;
		
		$bandwidth_slot		=	md_sql("SELECT COUNT(*) as count FROM ".md_GetDatabaseName('bandwidth')." WHERE contentarchive = '".(int)$contentarchiveid."' AND date='".$date."'");
		
		if ( $md_sql_row[$bandwidth_slot]['count'] == 0 )
		{
			md_sql_once("INSERT INTO ".md_GetDatabaseName('bandwidth')." (contentarchive, date, bandwidth) VALUES ('".$contentarchiveid."', '".$date."', '".$amount."')");
		}
		else
		{
			md_sql_once("UPDATE ".md_GetDatabaseName('bandwidth')." SET bandwidth = bandwidth + '".$amount."' WHERE contentarchive = '".$contentarchiveid."' AND date='".$date."'");
		}
		
		md_clearslot($bandwidth_slot);		
	}

	function md_creditbandwidth($contentarchiveid, $amount)
	{
		md_creditbandwidthdb(0, $amount, '1970-01-01'); // Global Variable for this content server
		md_creditbandwidthdb(0, $amount, md_gettoday()); // Today for this content server
		md_creditbandwidthdb($contentarchiveid, $amount, '1970-01-01'); // Global Variable for this product
		md_creditbandwidthdb($contentarchiveid, $amount, md_gettoday()); // Today for this product		
	}

?>